#pragma once

#include "Thread.hpp"
#include "LockGuard.hpp"
#include <vector>
#include <queue>
#include <mutex>
#include <pthread.h>
#include <unistd.h>

using namespace ThreadNs;

// 定义线程总数
const int gnum = 3;

template <class T>
class ThreadPool;

template <class T>
class ThreadData
{
public:
    ThreadPool<T> *threadpool;
    std::string name;

public:
    ThreadData(ThreadPool<T> *tp, const std::string &n) : threadpool(tp), name(n)
    {
    }
};

template <class T>
class ThreadPool
{
    private:
    static void *handlerTask(void *args) // 定义这个函数就是为了传给start_routine的 
    // 所以必须是static 只有1个参数 args
    {
        ThreadData<T> *td = (ThreadData<T> *)args;
        while(true)
        {
            T t;
            {
                LockGuard lockguard(td->threadpool->mutex());
                while(td->threadpool->isQueueEmpty())
                {
                    td->threadpool->threadWait();
                }
                t = td->
            }
        }
    }

private:
    int _num;                       // 线程数
    std::vector<Thread *> _threads; // 线程池
    std::queue<T> _task_queue;      // 任务队列

    pthread_mutex_t _mutex; // 锁
    pthread_cond_t _cond;   // 条件变量

    static ThreadPool<T> *tp;
    static std::mutex _singlock;
};

template <class T>
ThreadPool<T> *ThreadPool<T>::tp = nullptr;

template <class T>
std::mutex ThreadPool<T>::_singlock;